<?php
 include("../../includes/global_files/tables.inc");
include(DOCINCLUDES."pagesettings/master.inc");
include(DOCINCLUDES."global_files/global_js_form.inc");
include(DOCINCLUDES."global_files/global_functions.inc");
include(DOCINCLUDES."global_files/global_report.inc");
include(DOCINCLUDES."global_files/global_errorpage.inc");
$relation=($_REQUEST["rel_type"])?$_REQUEST["rel_type"]:"buy";
$action=($_REQUEST["action"])?$_REQUEST["action"]:"ent";

// $form = new cForm();
// $db     = new cDatabase($company_id);
// $sql    = new pgSql();
$report = new cReport();
$report->sql=$sql;
$report->db=$db;
// $db->setSearchPath();
// $dv=new cDataValidation();

if($_POST)
	{
	$dv->validations["code"]=array("isEmpty"=>"Enter Code");
	$dv->validations["company_name"]=array("isEmpty"=>"Enter Company Name");
	$dv->validate($_POST);
		if(!$dv->errors)
			{
			$db->beginTransaction();
				$commercial_details["company_code"]=$_POST["code"];
				$commercial_details["company_name"]=$_POST["company_name"];
				$sql->table ="_mcompany";
				$sql->column =$commercial_details;
				$sql->generateInsertQuery();
				$db->query = $sql->query;
				$db->runQuery();
			if(!$db->errors)
				{
				$db->endTransaction();
				unset($_POST);
				header("Location:master_company.php");
				exit;
				} 
			}
	}
$page->title=$page->heading="Company Details";
$page->doHeaderHtml();
	$form->properties = array("name"=>"master_company","method"=>"POST","action"=>$_SERVER["PHP_SELF"]);
	echo $form->startForm();

//         $form->properties=array("type"=>"hidden","name"=>"relation","value"=>$relation);
//         echo $form->generateInputTag();
	$form->properties = array("name"=>"code","type"=>"text","size"=>"15");
	$comm_list[0]["Code"] = $form->generateInputTag();

	$form->properties = array("name"=>"company_name","type"=>"text","size"=>"35");
	$comm_list[0]["Company Name"] = $form->generateInputTag();
	
	$report->customization["table_style"]="width:30%; border-style:solid; border-width:thin; border-collapse:collapse;";
	$report->customization["tr_style"]="border-style:none; border-width:thin; border-collapse:collapse";
	$report->title="Company Entry";
	$report->highlight=true;
	$report->data=$comm_list;
	echo "<div align=\"center\">";
	$report->doVerticalTable();
	$form->properties = array("name"=>"save","type"=>"submit","Value"=>"Save");
	echo $form->generateInputTag();
	echo $form->endForm();
	
	$db->query="SELECT company_code as \"Code\",company_name as \"Company\" from _mcompany order by company_code;";
	$db->runQuery();
	$view_list=$db->returnArrays();
	$report->customization["table_style"]="width:50%; border-style:solid; border-width:thin; border-collapse:collapse;";
	$report->customization["tr_style"]="border-style:none; border-width:thin; border-collapse:collapse";
	$report->title="Company Details";
	$report->data=$view_list;
	echo "</br>";
	echo "</br>";
	$report->setNA();
	$report->doHorizontalTable();
	echo "</div><br />";
$page->doFooterHtml();
?>
